﻿
//下拉筐学习语言值
var SelLearnVal = "";
//下拉筐使用语言值
var SelSpeakVal = "";
//下拉筐学习语言文本
var SelLearnText = "";
//下拉筐使用语言文本
var SelSpeakText = "";

function onsuccData(result)
{
    if(SelSpeakVal!="")
    {
        $get("LearnForSpeak").style.display="";
        RendTitle("LeSpTitle");
        RendList(result[0],"LearnSpeak");        
        RendTitle("LearnRTitle");        
    }
    else
    {
        $get("LearnForSpeak").style.display="none";
        
    }
	RendTitle("LearnRTitle"); 
    RendList(result[1],"LeResList");
    if(result[2].length==0)
    {
        $get("PopularRList").style.display="none";
    }
    else
    {            
        RendTitle("PopularRTitle");
        RendList(result[2],"PRList");
        $get("PopularRList").style.display="";
    }
    $get("lodingID").style.display="none";
}
function RendTitle(divID)
{
    var domDiv = $get(divID);
    if(domDiv!=null)
    {    
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        }   
        switch(divID)
        {
            case "LeSpTitle":                      
                if($get("LeSpTitleItem")==null) return;        
                var item= $get("LeSpTitleItem").innerHTML; 
                var tmp = item.replace(/\$LearnLanguage\$/gi,SelLearnText).replace(/\$BaseLanguage\$/gi,SelSpeakText);               
                     tmp = tmp.replace(/\$learnuse\$/gi,RS005.replace("{0}",SelLearnText).replace("{1}",SelSpeakText));      
               domDiv.innerHTML = tmp; 
                break;
            case "LearnRTitle":                       
                if($get("LearnRTitleItem")==null) return;        
                var item= $get("LearnRTitleItem").innerHTML; 
                var tmp = item.replace(/\$LearnLanguage\$/gi,SelSpeakVal!=""?RS006.replace("{0}",SelLearnText):RS003.replace("{0}",SelLearnText));      
                domDiv.innerHTML = tmp; 
                break;
            case "PopularRTitle":
                if($get("PopularRTitleItem")==null) return;        
                var item= $get("PopularRTitleItem").innerHTML; 
                var tmp = item.replace(/\$LearnLanguage\$/gi,SelLearnText);
	                     tmp = tmp.replace(/\$most\$/gi,RS007.replace("{0}",SelLearnText));      
                domDiv.innerHTML = tmp; 
                break;
        }
    }
}
function RendList(list,divID)
{   
    var domDiv = $get(divID);
    var listLength = list.length;    
    if(domDiv!=null)
    {    
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        } 
        switch(divID)
        {
            case "LearnSpeak":
                if($get("LearnSpeakItem")==null) return;        
                var item= $get("LearnSpeakItem").innerHTML;
                var listBuilder = new Sys.StringBuilder();
                for (var index = 0; index < listLength; index++) 
                {
                    var obj = list[index];                     
                    var tmp = item.replace(/\$LearnLan\$/gi,obj.LanguageLearn).replace(/\$BaseLan\$/gi,obj.BaseLanguage).replace(/\$PageTitle\$/gi,obj.PageTitle);
                    tmp = tmp.replace(/\$PageResourcesCount\$/gi,obj.PageResourcesCount).replace(/\$PageID\$/gi,obj.PageID).replace(/\$LearnLanguage\$/gi,SelLearnText).replace(/\$BaseLanguage\$/gi,SelSpeakText);      
	                     tmp = tmp.replace(/\$learnusing\$/gi,RS004.replace("{0}",SelLearnText).replace("{1}",GetLanguageLabel("selLearnL",obj.BaseLanguage)));      
                    listBuilder.append(tmp);
                }
                var sTemp = listBuilder.toString();
                domDiv.innerHTML = sTemp;
                break;
            case "LeResList": 
                if($get("LeResListItem")==null) return;        
                var item= $get("LeResListItem").innerHTML;
                var listBuilder = new Sys.StringBuilder();                                        
                for (var index = 0; index < listLength; index++) 
                {
                    var obj = list[index];                     
                    var tmp = item.replace(/\$LearnLan\$/gi,obj.LanguageLearn).replace(/\$BaseLan\$/gi,obj.BaseLanguage).replace(/\$PageTitle\$/gi,obj.PageTitle);
                    tmp = tmp.replace(/\$PageResourcesCount\$/gi,obj.PageResourcesCount).replace(/\$PageID\$/gi,obj.PageID);
	                     tmp = tmp.replace(/\$learnusing\$/gi,RS004.replace("{0}",SelLearnText).replace("{1}",GetLanguageLabel("selLearnL",obj.BaseLanguage)));      
                    listBuilder.append(tmp);
                }
                var sTemp = listBuilder.toString();
                domDiv.innerHTML = sTemp;
                break;
            case "PRList":                
                if($get("PRListItem")==null) return;        
                var item= $get("PRListItem").innerHTML;
                var listBuilder = new Sys.StringBuilder();                                        
                for (var index = 0; index < listLength; index++) 
                {
                    var obj = list[index];                     
                    var tmp = item.replace(/\$ResID\$/gi,obj.ResID).replace(/\$Url\$/gi,obj.Url).replace(/\$Name\$/gi,obj.Name);
                    tmp = tmp.replace(/\$Totalhits\$/gi,obj.Totalhits).replace(/\$LanguageLearn\$/gi,GetLanguageLabel("selLearnL",obj.LanguageLearn)).replace(/\$BaseLanguage\$/gi,GetLanguageLabel("selLearnL",obj.BaseLanguage));
	                     tmp = tmp.replace(/\$learnusing\$/gi,RS004.replace("{0}",SelLearnText).replace("{1}",GetLanguageLabel("selLearnL",obj.BaseLanguage)));      
                    listBuilder.append(tmp);
                }
                var sTemp = listBuilder.toString();
                domDiv.innerHTML = sTemp;
                break;
        }        
    }    
}
//选择下拉筐语言
function SelectLearn()
{
    $get("lodingID").style.display="";
    SelLearnVal = $get("selLearnL").value;
    SelLearnText = $get("selLearnL").options[$get("selLearnL").selectedIndex].text;    
    SelSpeakVal = $get("selSpeakL").value;
    SelSpeakText = $get("selSpeakL").options[$get("selSpeakL").selectedIndex].text;    
    WebServices.WWW.Resources.GetResources(SelLearnVal,SelSpeakVal,onsuccData);
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
